package com.micosco.taskremind.ui;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;

import com.micosco.taskremind.R;

import java.util.Formatter;

public class TimePickerFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener {
    @NonNull
    @Override
    public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
        return new TimePickerDialog(getActivity(), this, 0, 0,
                DateFormat.is24HourFormat(getActivity()));
    }

    @SuppressLint("DefaultLocale")
    @Override
    public void onTimeSet(android.widget.TimePicker timePicker, int i, int i1) {
        Activity parent = getActivity();
        if (parent != null) {
            TextView expireTime = parent.findViewById(R.id.expire_time);
            expireTime.setText(String.format("%02d:%02d",
                    timePicker.getHour(), timePicker.getMinute()));
        }
    }
}
